package com.example.demo.core;

import com.example.demo.channel.service.ChannelInterface;
import com.example.demo.controller.DynamicLoadController;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 项目启动加载 通道信息
 */
@Component
public class LoadCommandLineRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        ApplicationContext applicationContext = UserApplicationContext.getApplicationContext();
        String[] beans = applicationContext.getBeanDefinitionNames();
        for (String bean : beans) {
            Object rBean = applicationContext.getBean(bean);
            if (rBean instanceof ChannelInterface) {
               DynamicLoadController.put(rBean.getClass().getSimpleName(), (ChannelInterface) rBean);
            }
        }

    }
}